package com.appspot.redalert;


import android.util.Log;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class LocalService extends Service {
	private static final String LOG_TAG = "redalert-service";

	@Override
	public void onStart(Intent intent, int id) {
		super.onStart(intent, id);
		Log.d(LOG_TAG, "onStart");
	}
	
	
    @Override
    public void onCreate() {
    	super.onCreate();
    	Log.d(LOG_TAG, "onCreate");
    	
        notification_manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

        // This is who should be launched if the user selects our persistent
        // notification.
        //Intent intent = new Intent();
        //intent.setClass(this, LocalServiceController.class);

        // Display a notification about us starting.  We use both a transient
        // notification and a persistent notification in the status bar.
        Notification notification = new Notification(R.drawable.icon
        		
        		, "RedAlert Service Started", System.currentTimeMillis());
        try {
        	PendingIntent pi = PendingIntent.getService(this, 0, new Intent(), PendingIntent.FLAG_CANCEL_CURRENT|PendingIntent.FLAG_ONE_SHOT);
        	notification.setLatestEventInfo(this, "relaunch app",
        		      "relaunch with dummy extra", pi);
        notification_manager.notify(1, notification);
        } catch(Throwable e) {
        	Log.e(LOG_TAG, "error" + notification.toString(), e);
        }
        		/*
        		R.string.local_service_started,
                   getText(R.string.local_service_started),
                   NotificationManager.LENGTH_SHORT,
                   new Notification(
                       R.drawable.stat_sample,
                       getText(R.string.local_service_label),
                       intent,
                       null,
                       null));*/
    }

    public IBinder  onBind(Intent intent) {
    	return binder;
    }

    @Override
    public void onDestroy()
    {
    	/*
        // Cancel the persistent notification.
        //notification_manager.cancel(R.string.local_service_started);

        // Tell the user we stopped.
        mNM.notifyWithText(R.string.local_service_stopped,
                   getText(R.string.local_service_stopped),
                   NotificationManager.LENGTH_SHORT,
                   null);
                   */
    }
/*
    @Override
    public IBinder getBinder()
    {
        return mBinder;
    }

    // This is the object that receives interactions from clients.  See
    // RemoteService for a more complete example.
    private final IBinder mBinder = new BinderNative()
    {
        @Override
        protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) {
            return super.onTransact(code, data, reply, flags);
        }
    };
*/
    private NotificationManager notification_manager;
    private ServiceInterface.Stub binder;
}


